<?php
if(file_exists(__DIR__.'/../Database/DBCon.php'))
{
	require_once(__DIR__.'/../Database/DBCon.php');
} else
{
 require_once(__DIR__.'/Database/DBCon.php');
}

class UserDetails
{
    // property declaration
	public $UserId;
    public $UserName;
	public $Password;
	public $FullName;
	public $EmailAddress;
	public $Address;
	public $City;
	public $State;
	public $Country;
	public $PinCode;
	public $Mobile;
	public $UserType;
	public $Longitude;
	public $Latitude;
	
    // method declaration
    public function ValidateUser() {
		session_start();
		$qValidate ="SELECT UserId FROM userlogin WHERE UserName='".$this->UserName."' AND Password='".$this->Password."';";
		$resultVal = mysql_query($qValidate);
		$rUser = mysql_fetch_assoc($resultVal);
		$this->UserId=$rUser['UserId'];
		if($this->UserId>0)
		{
			$qUdetail = "SELECT * FROM userdetail WHERE UserId=".$this->UserId.";";
			$resUdetail = mysql_query($qUdetail);
			$rowUdetail = mysql_fetch_assoc($resUdetail);
			$this->UserId=$rowUdetail['UserId'];
			$this->FullName = $rowUdetail['FullName'];
			$this->EmailAddress = $rowUdetail['EmailAddress'];
			$this->Address = $rowUdetail['Address'];
			$this->City = $rowUdetail['City'];
			$this->State = $rowUdetail['State'];
			//$this->Country = $rowUdetail['Country'];
			//$this->PinCode = $rowUdetail['PinCode'];
			//$this->Mobile = $rowUdetail['Mobile'];
			$this->UserType = $rowUdetail['UserType'];
			//$this->Longitude = $rowUdetail['Longitude'];
			//$this->Latitude = $rowUdetail['Latitude'];
			
			$_SESSION["user"] = $this->FullName;
			$URL="index.php";
			echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">';
		} else
		{
		 echo " Invalid Login Detail";
		}
    }
	public function RegisterUser(){
	$CurrentDateTime = date("D M d, Y G:i a");
	$qLogin = "INSERT INTO userlogin(UserName,Password) VALUES('".$this->UserName."','".$this->Password."');";
	$res = mysql_query($qLogin);
	if($res)
	{
		$qSelectUserId ="SELECT UserId FROM userlogin WHERE UserName='".$this->UserName."';";
		$result = mysql_query($qSelectUserId);
		$row = mysql_fetch_assoc($result);
		$this->UserId=$row['UserId'];
		if($this->UserId>0)
		{
			$qDetail ="INSERT INTO userdetail(UserType,FullName,Address,City,State,EmailAddress,UserId,CreateDate) VALUES('".$this->UserType."','".$this->FullName."','".$this->Address."','".$this->City."','".$this->State."','".$this->EmailAddress."',".$this->UserId.",'".$CurrentDateTime."');";
			$resDetail = mysql_query($qDetail);
			if($resDetail)
			{
				$URL="index.php?Login";
				echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">'; 
			}
		}
		//echo $qLogin;
		//echo $qSelectUserId;
		//echo $qDetail;
	}
//	mysql_close($connection);
	}
	
}
?>